package org.xwb.springcloud.messagetype.topic;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
import org.xwb.springcloud.constant.MqConstant;

import javax.annotation.Resource;

/**
 * @author 10564
 */
@Component
public class TopicQueueProducer {
    private static final Logger log = LoggerFactory.getLogger(TopicQueueProducer.class);

    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送topic主体消息队列，匹配一个 或者匹配多个
     * @param message 消息
     * @param routingKey 路由key
     */

    public void senderTopicQueueRoutingMatching(String message,String routingKey) {
        log.info("\n主题模式 生产者发送消息 message:{}\n",message);
        log.info("\n主题模式 Routing:【{},{}】,当前的消息routing:{}\n",MqConstant.TOPIC_ROUTING_KEY_MATCHING_ONE,MqConstant.TOPIC_ROUTING_KEY_MATCHING_ONE_OR_MORE,routingKey);
        //参数1：交换机名称
        //TODO 参数2：路由key * 匹配一个 # 匹配一个或者多个【此处的key是匹配MqConstant.TOPIC_ROUTING_KEY_MATCHING_ONE或者是TOPIC_ROUTING_KEY_MATCHING_ONE_OR_MORE】
        //参数3：消息
        // topic_exchange交换机  需要指定路由key  绑定到该交换机且符合路由key的队列都会收到消息
        rabbitTemplate.convertAndSend(MqConstant.TOPIC_EXCHANGE_NAME,routingKey,message);
    }
}
